#include "lowpower.h"
#include "stm32f4xx_ll_pwr.h"
#include "stm32f4xx_hal_pwr.h"
#include "stdio.h"

unsigned int LpcInit(void)
{
    return 0;
}

unsigned int LpcSetType(LpcType type)
{
    if(type==LIGHT_SLEEP){
        printf("enter light sleep mode...\n");
        // 暂停定时器
        HAL_SuspendTick();
        // 进入睡眠模式
        HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON,PWR_SLEEPENTRY_WFI);
        // 恢复定时器
        HAL_ResumeTick();
    }
    else if(type==DEEP_SLEEP){
        printf("enter deep sleep mode, for stm32 is stop mode ...\n");
        // 清除唤醒标志
        __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
        // 进入停止模式
        HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON,PWR_STOPENTRY_WFI);
        // 唤醒后需要重新配置HSI
        SystemClock_Config();
    }
    else if(type==STANDBY){
        printf("enter more deep sleep, for stm32 is standby mode ...\n");
        // 禁用唤醒引脚
        HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN1);
        // 清除唤醒标志
        __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
        // 启用唤醒引脚
        HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1);
        // 进入停止模式
        HAL_PWR_EnterSTANDBYMode();
    }
    return 0;
}

